#include<func.h>

void *pthread_func(void *p)
{
    printf("I am child thread %ld\n",(long)p);
    return NULL;
}

//创建两个子线程,1号线程打印我是线程1，2号打印我是线程2
int main()
{
    pthread_t pthid[2];
    int ret;
    long i;
    for(i=0;i<2;i++)
    {
        ret=pthread_create(pthid+i,NULL,pthread_func,(void *)i);
        THREAD_ERR_CHECK(ret,"pthread_create")
    }
    //打印都是2的原因：子线程去打印时，主线程把i改为2
    for(i=0;i<2;i++)
    {
        ret=pthread_join(pthid[i],NULL);
        THREAD_ERR_CHECK(ret,"pthread_join")
    }
    printf("I am main thread\n");
    return 0;
}
    